﻿Shader "Hidden/Universal Render Pipeline/DirectionalBlur"
{
	
	Properties
    {
        _MainTex("Source", 2D) = "white" {}
    }
	
	HLSLINCLUDE
	
	#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
    #include "Packages/com.unity.render-pipelines.universal/Shaders/PostProcessing/Common.hlsl"

	TEXTURE2D(_MainTex);		SAMPLER(sampler_MainTex);
	half4 _Params;	
	#define _Iteration _Params.x
	#define _Direction _Params.yz

	struct Attributes1
	{
		float4 positionOS       : POSITION;
		float2 uv               : TEXCOORD0;
		UNITY_VERTEX_INPUT_INSTANCE_ID
	};

	Varyings Vert1(Attributes1 input)
	{
		Varyings output;
		UNITY_SETUP_INSTANCE_ID(input);
		UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output); 

		output.positionCS = TransformObjectToHClip(input.positionOS);
    	output.texcoord = input.uv;
		
		return output;
	}
	
	half4 DirectionalBlur(Varyings i)
	{
		half4 color = half4(0.0, 0.0, 0.0, 0.0);

		for (int k = -_Iteration; k < _Iteration; k++)
		{
			color += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, i.texcoord - _Direction * k);
		}
		half4 finalColor = color / (_Iteration * 2.0);

		return finalColor;
	}

	half4 Frag(Varyings i): SV_Target
	{
        return DirectionalBlur(i);
	}

	ENDHLSL
	
	SubShader
	{
		Tags { "RenderType" = "Opaque" "RenderPipeline" = "UniversalPipeline"}
		Cull Off ZWrite Off ZTest Always
		
		Pass
		{
			Name "DirectionBlur"
			HLSLPROGRAM
			
			#pragma vertex Vert1
			#pragma fragment Frag
			
			ENDHLSL
			
		}
	}
}

    